package com.xjh.basestudy.javabase.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

//通过反射实现如下操作
//Student s = new Student("徐建华",20,"西安"）;
//System.out.println(s);
public class reflectexercise1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //获取Class对象
        Class<?> c = Class.forName("heimaliuyi.reflect.Student");

        //目标：获取public Student(String name, int age, String address)构造方法
        //获取单个构造方法对象，注意参数的写法 数据类型.class
        Constructor<?> con = c.getConstructor(String.class,int.class,String.class);
        //获取obj对象
        Object obj = con.newInstance("徐建华",20,"西安");
        System.out.println(obj);


    }
}
